package com.dyit.springcloud.hospital.web.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;

public class Code {
    public static int create(OutputStream out){
        int s=0;
        try{
            BufferedImage image = new BufferedImage(120,80,BufferedImage.TYPE_INT_RGB);

            Graphics graphics = image.createGraphics(); //画笔
            graphics.fillRect(0,0,120,80);

            graphics.setColor(Color.RED);
            graphics.setFont(new Font("华文行楷",Font.PLAIN,34));

            s = new Random().nextInt(9000)+1000;

            graphics.drawString(s+"",50,80);


            ImageIO.write(image,"png",out);
        }catch (IOException e){
            e.printStackTrace();
        }
        System.out.println(s);
        return s;
    }

}
